<template>
  <el-row>
    <el-col :span="24">
      <el-form
        :inline="true"
        :model="materialSearchObj"
        class="search_prod tl"
        @submit.native.prevent
      >
        <el-form-item label="商品标题：">
          <el-input
            size="small"
            clearable
            v-model="materialSearchObj.title"
            :placeholder="searchtitle"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="商品类型："
          v-if="this.$route.path != '/index/page/merchant' && isAllSearch"
        >
          <el-radio-group
            v-model="materialSearchObj.is_supplier"
            @change="changeShop"
          >
            <el-radio label="2">所有商品</el-radio>
            <el-radio label="1">供应商商品</el-radio>
            <el-radio label="3">自营商品</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="店铺名称："
          v-if="materialSearchObj.is_supplier == 1 && isAllSearch"
        >
          <el-input
            size="small"
            clearable
            v-model="materialSearchObj.sid_cn"
            :placeholder="searchtitle"
          ></el-input>
        </el-form-item>
        <el-form-item label="活动场景：" v-if="isAllSearch">
          <el-select
            v-model="materialSearchObj.types"
            size="small"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="(item, k) in activity_option"
              :key="k"
              :label="item"
              :value="k"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-row class="tl">
            <el-col :span="24">
              <el-button
                :loading="$store.state.isLoading"
                size="small"
                class="top_weiy"
                type="primary"
                @click="onSubmit"
                >查询</el-button
              >
              <el-button
                :loading="$store.state.isLoading"
                size="small"
                class="top_weiy"
                type="primary"
                @click="delSubmit"
                >一键清除</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>
<script>
export default {
  name: "",
  props: {
    searchtitle: {
      type: String,
      default: "标题",
    },
    isAllSearch: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      materialSearchObj: {
        title: "",
        is_supplier: "2",
        types: "",
      },
      activity_option: [],
    };
  },
  created() {
    this.get_activity_option();
  },
  methods: {
    get_activity_option() {
      this.$api.getShops.get_activitylist({}).then((res) => {
        if (res.data.code == 200) {
          this.activity_option = res.data.result;
        }
      });
    },
    changeShop() {
      this.$emit("sendSearch", this.materialSearchObj);
    },
    delSubmit() {
      this.materialSearchObj = {
        title: "",
        types: "",
        is_supplier: "2",
      };
      this.$emit("sendSearch", this.materialSearchObj);
    },
    onSubmit() {
      this.$emit("sendSearch", this.materialSearchObj);
    },
  },
};
</script>
